package com.vidyu.businesslayer.businesscomponents;

import com.vidyu.businesslayer.businessentities.Skill;
import com.vidyu.datalayer.dataaccesscomponents.SkillDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created with IntelliJ IDEA.
 * User: eyalsa
 * Date: 4/6/13
 * Time: 3:30 PM
 * To change this template use File | Settings | File Templates.
 */
@Component
public class SkillHandler {

    @Autowired
    private SkillDao skillDao;

    public long addSkill(String title, String skillDesc){
        Skill skill =  skillDao.getSkillDesc(title);
        long id;
        if (skill == null) {
             id = skillDao.save(new Skill(title, skillDesc));
        } else {
            skill.setTitle(skillDesc);
            skillDao.update(skill);
            id = skill.getId();
        }
        return id;
    }

}
